<?php
class Application_Modules_Admin_Model_Carga
{
	public  function select($where = null, $order = null, $limit = null)
   	{
      	$dao = new Application_Model_DbTable_PosicaoCarga();
      	$select = $dao->select()->from($dao)->order($order)->limit($limit);
      	if(!is_null($where)){
         	$select->where($where);
      	}
      	return $dao->fetchAll($select)->toArray();
   	}
 
   	public function find($id)
   	{
      	$dao = new Application_Model_DbTable_PosicaoCarga();
      	$arr = $dao->find($id)->toArray();
      	return $arr[0];
   	}
 
   	public function insert(array $request)
   	{
      	$dados = array(
         	'id_cargapos' => $request['id_cargapos'],
         	'codigo' => $request['codigo'],
         	'lat' => $request['lat'],
      		'log' => $request['log'],
      		'data' => new Date()
      	);
      	return $this->insert($dados);
   	}
   
   	public function  update(array $request)
   	{
   		$dao = new Application_Model_DbTable_PosicaoCarga();
   		$dados = array(
        	'id_cargapos' => $request['id_cargapos'],
         	'codigo' => $request['codigo'],
         	'lat' => $request['lat'],
      		'log' => $request['log'],
      		'data' => new Date()
   		);
   		$where = $dao->getAdapter()->quoteInto("id_cargapos = ?", $request['id_cargapos']);
   		$dao->update($dados, $where);
   	}
   
   	public function delete($id)
   	{
   		$dao = new Application_Model_DbTable_PosicaoCarga();
   		$where = $dao->getAdapter()->quoteInto("id_cargapos = ?", $id);
   		$dao->delete($where);
   	}

}